//
//  FFPanelRedpacketFuncItem.m
//  LiMaoTransfer
//
//  Created by tt on 2022/5/7.
//

#import "FFPanelRedpacketFuncItem.h"
#import "FFSendRedPacketsVC.h"
#import "FFRedPacketsModule.h"
#import "FFRedPacketsContent.h"
@implementation FFPanelRedpacketFuncItem


- (NSString *)sid {
    return @"apm.limao.redpacket";
}

- (UIImage *)itemIcon {
    return [self imageName:@"func_redpacket_normal"];
}

- (void)onPressed:(UIButton *)btn {
    
    __weak typeof(self) weakSelf = self;
    id<WKConversationContext> context = self.inputPanel.conversationContext;
    // 判断群和单聊 1单聊 2群聊
    int type = context.channel.channelType;
    
    // 跳转
    FFSendRedPacketsVC *vc = [[FFSendRedPacketsVC alloc] init];
    vc.channel = context.channel;
    vc.redPacketsType = type;
    vc.onDealloc = ^{
        btn.selected = false;
    };
    if (type == 2) {
        NSInteger memberCount =  [[WKSDK shared].channelManager getMemberCount:context.channel];
        vc.membersCount =memberCount;
    }
    vc.sendPacketComplete = ^(NSDictionary  * _Nonnull dict) {
        [weakSelf sendRedPackets:context dict:dict];
    };
    [[WKNavigationManager shared] pushViewController:vc animated:YES];
}
- (NSString *)title {
    return LLang(@"红包");
}

// 发红包
- (void)sendRedPackets:(id<WKConversationContext>)context dict:(NSDictionary *)dict {
    __weak typeof(context) weakContext = context;
    
    NSString *redPacketNo = dict[@"redpacket_no"];
    NSString *blessing = dict[@"blessing"];
    [weakContext sendMessage:[FFRedPacketsContent redPacketNo:redPacketNo blessing:blessing]];
}

-(UIImage*) imageName:(NSString*)name {
    return [[WKApp shared] loadImage:name moduleID:[FFRedPacketsModule gmoduleId]];
}


@end
